Method for determining transparency in images extraction

ABSTRACT

A method for determining transparency of images in extraction comprises various steps, including set transparent areas in Image 1 to black; set transparent areas in Image 2 to white; to perform an “exclusive or” operation on Image 1 and Image 2: subtract 1 from the resulting bitmap of the “exclusive or” operation, wherein the resulting bitmap after the “subtraction” operaton is called first mask bitmap; fill a first temporary bitmap with pixels all set to (254, 254, 254); perform an “exclusive or” operation on the first temporary bitmap and the bitmap for Image 1; fill a second temporary bitmap with pixels all set to (0, 0, 0); divide the resulting bitmap of the “exclusive or” operation on the first temporary bitmap and the bitmap for Image 1 by the second temporary bitmap, wherein the resulting bitmap after the “division” operation is called second mask bitmap; perform an “or” operation on the second mask bitmap and the original bitmap for Image 1; and perform an “or” operation on the first mask bitmap and the second mask bitmap. As a result, the pixels in the exporting image which have rgb values (254, 254, 254) are transparent; and the pixels in the exporting image, corresponding to the pixels in image 1 that had rgb values (254, 254, 254), now have rgb values (255, 255, 255).

COPYRIGHT NOTICE

[0001] A portion of the disclosure of this patent document containsmaterial that is subject to copyright protection. The copyright ownerhas no objection to the facsimile reproduction by anyone of the patentdocument or the patent disclosure, as it appears in the Patent andTrademark Office file or records, but otherwise reserves all copyrightrights whatsoever.

BACKGROUND OF THE INVENTION

[0002] 1. Technical Field

[0003] The invention relates generally to image processing technology.More particularly, the invention relates to a process and method foralgorithmic determination of image transparency.

[0004] 2. Description of Prior Art

[0005] When extracting images from another program, transparency needsto be handled correctly because the transparent portion of the imagesmay change to another color during transformation.

[0006] One solution is to analyze each byte of the two input imagesdirectly in the visual basic code, but that is too slow. The alternativesolution is to make use of the bitmap operations, which are faster, bysetting the transparent portions of the images to white during theextraction process. This solution is still problematic because whenmaking all white pixels transparent, any pixels that were white in theoriginal image will be also changed to be transparent in the exportedimage.

[0007] What is desired is to develop a process for determiningtransparency of exported images wherein transparency is not shown whereit should not be shown.

SUMMARY OF THE INVENTION

[0008] It has been determined that the transparent areas of images maybe set to a different color. This leads to the idea that first set thetransparent area of the image to white with rgb values (255, 255, 255)and extract the image, then set the transparent area to black with rgbvalues (0, 0, 0) and extract the image again, and finally compare thetwo resulting images such that the pixels that are different may bedetermined transparent.

[0009] The presently preferred embodiment of the invention determinestransparency when an image is extracted, wherein all transparent pixelsin the original image have rgb values (254, 254, 254) in the exportedimage, and any pixels with the rgb values (254, 254, 254) in theoriginal image have rgb values (255, 255, 255) in the exported image.These numbers (254 and 255) are chosen because of their binaryrepresentations: 254 is 11111110 in binary and 255 is 11111111 in binaryand because they are too similar for most users to be able to tell ifone is changed to another.

[0010] The invention provides a mechanism that starts by creating a maskbitmap where all transparent areas have rgb values (254, 254, 254) andall other pixels have rgb values (0, 0, 0). Then the original bitmap istaken and all pixels that had rgb values (254, 254, 254) are changed torgb values (255, 255, 255). Finally, the mask bitmap is applied to theresulting bitmap with an ‘or’ operation such that the set of pixels withrgb values (254, 254, 254) in the bitmap should be transparent. Becausethe pixels with rgb values (254, 254, 254) in the original bitmap hasbeen changed to rgb values (255, 255, 255), these pixels are not changedto be transparent in the exported image.

BRIEF DESCRIPTION OF THE DRAWINGS

[0011]FIG. 1 is a flow diagram illustrating a process according to theinvention, comprising various steps that collectively enable thefunctionality of the invention.

DETAILED DESCRIPTION OF THE INVENTION

[0012]FIG. 1 is a flow diagram illustrating a process according to theinvention, comprising various steps that collectively enable thefunctionality of the invention. In the process, bitmap operations of‘or’, ‘exclusive-or’, ‘divide’ and ‘subtract’ are used. These operationsare common to most graphics systems and are efficient for bitmaps. Inthe examples shown by a set of tables given below, only nine pixels areincluded, and only single bytes are used to represent pixels to make theprocess easy to understand. In the real implementation, the number ofpixels in an image is very large, and each pixel is represented by threebytes, one for each of red, green and blue.

[0013] The process according to the invention comprises the steps of:

[0014] Step 1: Create a First Mask Bitmap to Define the TransparentAreas

[0015] This step starts by combining two images (Image 1 and Image 2)with different background colors using an ‘exclusive or’ operation.

[0016] These two images have the same size and are the same except fortransparent areas. Table 1 shows the key referring to positions of 9pixels in the bitmap for the images. In image 1, all areas where shouldbe transparent are set to black (0, 0, 0) as shown in Table 2. In image2, all areas where should be transparent are set to white (255, 255,255) as shown in Table 3. TABLE 1 Key referring to positions in thebitmap 1, 1 2, 1 3, 1 1, 2 2, 2 3, 2 1, 3 2, 3 3, 3

[0017] TABLE 2 Bitmap for Image 1 wherein transparent pixels are set toblack (0, 0, 0) 0 0 0 128 255 0 128 128 254

[0018] TABLE 3 Bitmap Image 2 wherein transparent pixels are set towhite (255, 255, 255) 0 255 255 128 255 255 128 128 254

[0019] The ‘exclusive or’ operation on these two images creates twobinary results for each position: it is 1 if two values in a sameposition are different, and it is 0 if two values in a same position aresame.

[0020] Referring to Table 4, after the ‘exclusive or’ operation isperformed, the resulting rgb values at positions (2,1), (3,1) and (3,2)are set to white (255, 255, 255) because the corresponding bits in eachof these positions were different. All other areas are set to black (0,0, 0) because the corresponding values in two images were equal. TABLE 4Bitmap after ‘exclusive or’ operation on Image 1 and Image 2 0 255 255 00 255 0 0 0

[0021] Then, subtract 1 from the bitmap shown in Table 4. After the‘subtraction’ operation, all black pixels (0,0,0) remains unchanged, andall white pixels (255, 255, 255) are changed to quasi-white (254, 254,254). These pixels with rgb values (254, 254, 254) at positions (2,1),(3, 1) and (3,2) are transparent areas. The bitmap shown in Table 5 ishereby named as the first mask bitmap. TABLE 5 Bitmap after‘subtraction’ (First Mask Bitmap) 0 254 254 0 0 254 0 0 0

[0022] Step 2: Change Pixels in the Original Bitmap that had RGB Values(254, 254, 254) to Pixels with RGB Values (255, 255, 255)

[0023] Two sub-steps are used to change any pixels that were originallyquasi white (254, 254, 254) to white (255, 255, 255), so thattransparency is not shown where it should not be shown. This is anoperation on the original bitmap of Image 1, which had black pixelswhere the transparent areas should be shown. There may be other blackpixels that can be handled by this algorithm.

[0024] Step 2A: Create a Second Mask Bitmap

[0025] This sub-step comprises:

[0026] 1. Filling a first temporary bitmap with pixels that are all setto quasi-white (254, 254, 254) as shown in Table 6. TABLE 6 Firsttemporary bitmap 254 254 254 254 254 254 254 254 254

[0027] 2. Combining the first temporary bitmap shown in Table 6 with theoriginal bitmap for Image 1 shown in Table 2 using an ‘exclusive or’operation. In the resulting bitmap shown in Table 7, the correspondingareas where they were quasi-white (254, 254, 254) in the original bitmapfor image 1 shown in Table 2 now become black (0, 0, 0), and all otherareas have random values (i.e. anything but 0, 0, 0). TABLE 7 Theresulting bitmap after ‘exclusive or’ operation 254 254 254 126 1 254126 126 0

[0028] 3. Filling a second temporary bitmap with pixels that are all setto black pixels (0, 0, 0) as shown in Table 8. TABLE 8 Second temporarybitmap 0 0 0 0 0 0 0 0 0

[0029] 4. Dividing the resulting bitmap shown in Table 7 by the secondtemporary bitmap shown in Table 8. After the ‘division’ operation, anyblack pixels (0, 0, 0) in the bitmap shown in Table 7 now become white(255, 255, 255) and any pixels that were anything else become black (0,0, 0). The result of this operation shown in Table 9 is hereby named asthe second mask bitmap. TABLE 9 Mask bitmap after ‘division’ operation(Second Mask Bitmap) 0 0 0 0 0 0 0 0 255

[0030] Comparing Table 2 with Table 9, it is clear that any pixels thatwere originally quasi-white (254, 254, 254) in Image 1 (Table 2) are nowwhite (255, 255, 255) in the mask bitmap (Table 9) and all other pixelsin Image 1 (Table 2) are now black (0, 0, 0) in the mask bitmap (Table9).

[0031] Step 2B: Apply the Second Mask Bitmap to the Original Bitmap

[0032] This is to apply the second mask bitmap (Table 9) from Step 2A tothe original bitmap (Table 2) using an ‘or’ operation, wherein 0 or'dwith anything returns the original value, and 255 (binary 11111111) or'dwith anything returns 255.

[0033] After the ‘or’ operation, any pixels that were quasi-white (254,254, 254) in Table 2 now become white (255, 255, 255) and all otherpixels in Table 2 keep unchanged as shown in Table 10. In thisoperation, actually any pixels that had a byte with a value of 254 inTable 2 now is changed to a byte with a value of 255, which is almostindistinguishable in the exported image. TABLE 10 Apply second maskbitmap to the original bitmap with an ‘or’ operation 0 0 0 128 255 0 128128 255

[0034] Step 3: Apply First Mask Bitmap to Second Mask Bitmap

[0035] This is to apply the first mask bitmap from Step 1 shown in Table5 to the second mask bitmap from Step 2B shown in Table 10 using an ‘or’operation, wherein 0 or'd with anything returns the original value, and255 (binary 11111111) or'd with anything returns 255.

[0036] The result of the ‘or’ operation is the bitmap where the set ofpixels with rgb values (254, 254, 254) should be transparent. Thetransparent file is written out with that color marked as thetransparent color. Any pixels that originally had rgb values (254, 254,254) now have rgb values (255, 255, 255), a change that is very close tothe original and not visible to most users.

[0037] Table 11 shows the expected result from applying the process tothe two input bitmaps. The rgb values of the positions (1,2), (2,2),(1,3) and (2,3) in the exported image are unchanged from their originalvalues. The position at (3,3) has changed from rgb values (254, 254,254) to rgb values (255, 255, 255). This is desired because the image isto be saved for displaying all pixels with rgb values (254, 254, 254) astransparent and the pixel at the position (3,3) should not betransparent. The pixels at (2,1), (3,1) and (3,2) all have rgb values(254, 254, 254), which are treated as transparent. TABLE 11 Apply themask from Step 1 with an ‘or’ operation 0 254 254 128 255 254 128 128255

[0038] Table 12 is the VBScript code implementation of the processdescribed herein. TABLE 12 VBScript BEGIN MultiUse = −1  ′True ENDAttribute VB_Name = “SXKeitherizer” Attribute VB_GlobalNameSpace = FalseAttribute VB_Creatable = False Attribute VB_PredeclaredId = FalseAttribute VB_Exposed = False Option Explicit Private ConstTRANSPARENT_COLOR As Long = &HFEFEFE Private Const BACKUP_COLOR As Long= &HFFFFFF Private Const PIXEL_SCALE_MODE As Integer = 3 ′ Takes twoimages which are the same size and the same except for transparent ′areas and changes the first image 11 so that those transparent pixelsare set to ′ rgb(254, 254, 254). If there were any pixels originally atthat value, they will ′ have been changed to rgb(255, 255, 255). ′ ′ Weassume that 11 has black pixels where there should be ′ transparency andthat 12 has white pixels where there should be transparency Public SubKeitherize(11 As LEAD, 12 As LEAD) 11.ScaleMode = PIXEL_SCALE_MODE12.ScaleMode = PIXEL_SCALE_MODE ′ get the dimensions Dim width As SingleDim height As Single width = 11.BitmapWidth height = 11.BitmapHeight ′create a mask where the transparent areas have pixels = FEFEFE and allothers areas ′ have pixels = 0 Dim transparentMask As LEAD SettransparentMask = CreateTransparentMask(11, 12) ′ bump any pixels in 11which are at transparentColor so that they are at backupColor Bump 11 ′set all pixels which are different in 11 and 12 equal totransparentColor in 11 11.Combine 0, 0, width, height,transparentMask.Bitmap, 0, 0, CB_OP_OR End Sub ′ changes 11 so that eachpixel that was at rgb(254, 254, 254) now becomes ′ rgb(255, 255, 255)Private Sub Bump(11 As LEAD) ′ create a mask of the same size as 11where each pixel that was at ′ TRANSPARENT_COLOR is now BACKUP_COLOR andall other pixels in the mask are 0 Dim mask As LEAD Set mask =CreateMask(11, TRANSPARENT_COLOR) ′ apply the mask to 11, bumping pixelsthat had the TRANSPARENT_COLOR value to the ′ BACKUP_COLOR. we arecounting on the fact that BACKUP_COLOR is all ones when we ′ do the or11.Combine 0, 0, 11.Bitmapwidth, 11.BitmapHeight, mask.Bitmap, 0, 0,CB_OP_OR End Sub ′ creates a new image of the same size as 11 where allpixels that were sourceColor in 11 ′ are set to white and all otherpixels are set to 0 Private Function CreateMask(11 As LEAD, sourceColorAs Long) As LEAD Dim mask As New LEAD mask.ScaleMode = PIXEL_SCALE_MODE′ set the width and height of the mask to match the input image Dimwidth As Single Dim height As Single width = 11.Bitmapwidth height =11.BitmapHeight mask.CreateBitmap width, height, 24 ′ after this, themask bitmap will have 0's where 11 had sourceColor pixels and ′ randomgarbage everywhere else mask.fill sourceColor mask.Combine 0, 0, width,height, 11.Bitmap, 0, 0, CB_OP_XOR ′ PENDING(greg) we could create asingle black image which we kept reusing ′ (growing as needed) if thatsped things up ′ create a black image of the same size for use below DimtempBlackImage As New LEAD tempBlackImage.ScaleMode = PIXEL_SCALE_MODEtempBlackImage.CreateBitmap width, height, 24 tempBlackImage.fill RGB(0,0, 0) ′ take all 0 pixels and make them into 255 pixels, and convert therandom garbage ′ into 0 pixels in a single step mask.Combine 0, 0,width, height, tempBlackImage.Bitmap, 0, 0, CB_OP_DIVDST Set CreateMask= mask End Function Private Function CreateTransparentMask(11 As LEAD,12 As LEAD) As LEAD ′ duplicate 11 and use it for the mask Dim mask AsNew LEAD maskScaleMode = PIXEL_SCALE_MODE mask.Bitmap = 11.Bitmap ′ getthe dimensions Dim width As Single Dim height As Single width =11.Bitmapwidth height = 11.BitmapHeight ′ combine the two bitmaps sothat pixels which were equal (non-transparent) ′ are 0 and pixels whichwere unequal (transparent) are white (0 xor 1 is 1) mask.Combine 0, 0,width, height, 12.Bitmap, 0, 0, CB_OP_XOR ′ subtract one from all thepixels, leaving 0 alone and reducing the 255s to 254 Dim tempImage AsNew LEAD tempImage.ScaleMode = PIXEL_SCALE_MODE tempImage.CreateBatmapwidth, height, 24 tempImage-fill &H10101 mask.Combine 0, 0, width,height, tempImage.Bitmap, 0, 0, CB_OP_SUBSRC Set CreateTransparentMask =mask End Function

[0039] In the process described herein, the value 254 is preferably usedfor the first mask bitmap i.e. the bitmap after ‘subtraction’ and thefirst temporary bitmap. In actuality, any eight-bit value close towhite, such as 253 or 252, may be used. The problem is that, in thefinal step, the pixels of that value need to be displaced to the valueof 255 and the further that value is from 255, the more noticeable thedifference will be.

[0040] This invention is preferably used in a system where the inputimages does not encode transparency directly, but rather outputstransparent pixels in a color that is specified. In addition, the outputimages need to be set in a format e.g. GIF, PNG, which assignstransparency to pixels based on their color. Finally, this invention isoptimized for situations where wholesale bitmap operations are fasterthan manipulating each byte individually. For instance, the MMXcapability of recent Pentium chips (Intel Corporation, Santa Clara,Calif.) has this optimization.

[0041] Although the invention is described herein with reference to thepreferred embodiment, one skilled in the art will readily appreciatethat other applications may be substituted for those set forth hereinwithout departing from the spirit and scope of the invention.

[0042] Accordingly, the invention should only be limited by the claimsincluded below.

What is claimed is:
 1. A method for determining transparency in imagesextraction, said method comprising the steps of: creating a first maskbitmap by combining a first image and a second image; wherein said firstimage and said second image have the same size and are the same exceptfor transparent areas; creating a second mask bitmap which displacespixels of first rgb values in said first image to second rgb values;applying said first mask bitmap to said second mask bitmap by performingan ‘or’ operation on said first mask bitmap and said second mask bitmap;wherein the pixels in the resulting bitmap of said ‘or’ operation whichhave said first rgb values are transparent; wherein the pixels in theresulting bitmap of said ‘or’ operation, corresponding to the pixels insaid first image that had said first rgb values, have said second rgbvalues; and identifying the pixels in the resulting bitmap of said ‘or’operation which have said first rgb values as transparent.
 2. The methodof claim 1, wherein said step of creating a first mask bitmap comprisesthe sub-steps of: setting transparent areas in said first image toblack; and setting transparent areas in said second image to white. 3.The method of claim 2 and further comprising the sub-step of: performingan ‘exclusive or’ operation on said first image and said second image.4. The method of claim 3 and further comprising the sub-step of:subtracting 1 from the resulting bitmap of said ‘exclusive or’operation; wherein the resulting bitmap of said ‘subtraction’ operationis said first mask bitmap.
 5. The method of claim 1, wherein said stepof creating a second mask bitmap comprises the sub-steps of: filling afirst temporary bitmap with pixels all set to rgb values (254, 254,254); and performing an ‘exclusive or’ operation on said first temporarybitmap and said first image.
 6. The method of claim 5 and furthercomprising the sub-steps of: filling a second temporary bitmap withpixels all set to rgb values (0, 0, 0); dividing the resulting bitmap ofsaid ‘exclusive or’ operation on said first temporary bitmap and saidfirst image by said second temporary bitmap; wherein the resultingbitmap of said ‘division’ operation is said second mask bitmap.
 7. Themethod of claim 6 and further comprising the sub-step of: applying saidsecond mask bitmap to said first image by performing an ‘or’ operationon said second mask bitmap and said first image; wherein the pixels withsaid first rgb values which first values are in said first image arechanged to said second rgb values which second values are (255, 255,255).
 8. A process for determining transparency in images extraction,said process comprising the steps of: creating a first mask bitmap bycombining a first image and a second image; wherein said first image andsaid second image have the same size and are the same except fortransparent areas; creating a second mask bitmap which displaces pixelsof rgb values (254, 254, 254) in said first image to rgb values (255,255, 255); applying said first mask bitmap to said second mask bitmap byperforming an ‘or’ operation on said first mask bitmap and said secondmask bitmap; wherein the pixels in the resulting bitmap of said ‘or’operation which have rgb values (254, 254, 254) are transparent; whereinthe pixels in the resulting bitmap of said ‘or’ operation, correspondingto the pixels in said first image that had rgb values (254, 254, 254),have rgb values (255, 255, 255); and identifying the pixels in theresulting bitmap of said ‘or’ operation which have said first rgb valuesas transparent.
 9. The process of claim 8, wherein said step of creatinga first mask bitmap comprises the sub-steps of: setting transparentareas in said first image to black; and setting transparent areas insaid second image to white.
 10. The process of claim 9 and furthercomprising the sub-step of: performing an ‘exclusive or’ operation onsaid first image and said second image.
 11. The process of claim 10 andfurther comprising the sub-step of: subtracting 1 from the resultingbitmap of said ‘exclusive or’ operation; wherein the resulting bitmap ofsaid ‘subtraction’ operation is said first mask bitmap.
 12. The processof claim 8, wherein said step of creating a second mask bitmap comprisesthe sub-steps of: filling a first temporary bitmap with pixels all setto rgb values (254, 254, 254); and performing an ‘exclusive or’operation on said first temporary bitmap and said first image.
 13. Theprocess of claim 12 and further comprising the sub-steps of: filling asecond temporary bitmap with pixels all set to rgb values (0, 0, 0);dividing the resulting bitmap of said ‘exclusive or’ operation on saidfirst temporary bitmap and said first image by said second temporarybitmap; wherein the resulting bitmap of said ‘division’ operation issaid second mask bitmap.
 14. The process of claim 13 and furthercomprising the sub-step of: applying said second mask bitmap to saidfirst image by performing an ‘or’ operation on said second mask bitmapand said first image; wherein the pixels with rgb values (254, 254, 254)in said first image is changed to rgb values (255, 255, 255).